#include "net/Timer.h"
#include <cassert>

namespace toym
{
namespace net
{

//////////////////////////////////////////
/////  Static members
//////////////////////////////////////////
std::atomic_int64_t Timer::s_seq(0);


/////////////////////////////////////////////
//////   Public member functions
/////////////////////////////////////////////
Timer::Timer(Timestamp when, double interval)
        : m_when(when),
          m_interval(interval),
          m_repeat(interval > 0.0),
          m_cb(),
          m_seq(s_seq++)
{}

void Timer::restart() {
    assert(m_repeat);
    m_when = m_when + Timestamp(m_when.getTick() + static_cast<int64_t>(m_interval*Timestamp::s_tickPerSecond));
}

} // namespace net

} // namespace toym
